﻿using System;
using System.Architecture;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using HDK.UI.Controls;
using Microsoft.Practices.Prism.Regions;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Group Detail Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234229

namespace HDK.Demo.Pages.Views
{
    /// <summary>
    /// A page that displays an overview of a single group, including a preview of the items
    /// within the group.
    /// </summary>
    [ExportView("Pages/GroupDetails", "", new string[] { "MainRegion" })]
    public sealed partial class GroupDetailPage : LayoutAwarePage, IView
                , INavigationAware
    {
        public GroupDetailPage()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
            // TODO: Assign a bindable group to this.DefaultViewModel["Group"]
            // TODO: Assign a collection of bindable items to this.DefaultViewModel["Items"]
        }

        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            this.DefaultViewModel["Group"] = "Group";
            this.DefaultViewModel["Items"] = new List<string> { "VAJAJA 1", "VAJAJA 1","VAJAJA 1","VAJAJA 1","VAJAJA 1"};
        }

        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;
        }

        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
        }

        private void itemGridView_ItemClick(object sender, ItemClickEventArgs e)
        {
        }

        private void itemGridView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.Parent != null)
            {
                var rn = RegionManager.GetRegionName(this.Parent);
                var rm = RegionManager.GetRegionManager(this.Parent);
                rm.RequestNavigate(rn, "//Pages/ItemDetails");
            }
        }

    }
}
